/**
 *
 * User: Zhikang.Peng
 * Date: 2018/04/11 14:38
 */
package stack

import "gitee.com/thghh/jvmgo/instructions/base"
import "gitee.com/thghh/jvmgo/rtda"

type SWAP struct {
	base.NoOperandsInstruction
}

/*
将栈最顶端的两个数值互换(数值不能是long或double类型的)
bottom -> top
[...][c][b][a]
          \/
          /\
         V  V
[...][c][a][b]
*/
func (self *SWAP) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	slot1 := stack.PopSlot()
	slot2 := stack.PopSlot()
	stack.PushSlot(slot1)
	stack.PushSlot(slot2)
}
